package com.ckerchina.admin.ckadmin.controller.console;


import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ckerchina.admin.ckadmin.controller.dto.MgrResponseData;
import com.ckerchina.admin.ckadmin.controller.dto.ResponseData;
import com.ckerchina.admin.ckadmin.dao.AgentUserDao;
import com.ckerchina.admin.ckadmin.dao.MgrMenuDAO;
import com.ckerchina.admin.ckadmin.dao.MgrUserAndMenuDAO;
import com.ckerchina.admin.ckadmin.dao.MgrUserDAO;
import com.ckerchina.admin.ckadmin.domain.mgr.MgrMenu;
import com.ckerchina.admin.ckadmin.domain.mgr.MgrUser;
import com.ckerchina.admin.ckadmin.domain.mgr.MgrUserAndMenu;
import com.ckerchina.admin.ckadmin.exception.ErrorCode;
import com.ckerchina.admin.ckadmin.exception.ZhuziException;
import com.ckerchina.admin.ckadmin.service.mgr.MgrUserDetail;
import com.ckerchina.admin.ckadmin.service.mgr.MgrUserService;

import cn.osworks.aos.core.asset.AOSJson;
import cn.osworks.aos.core.asset.AOSUtils;
import cn.osworks.aos.core.asset.WebCxt;
import cn.osworks.aos.core.typewrap.Dto;
import cn.osworks.aos.core.typewrap.Dtos;

/**
 * 基本操作相关功能。
 */
@Controller
public class MgrController {
	@Autowired
	private MgrUserDAO mgrUserDAO;
	@Autowired
	private MgrMenuDAO mgrMenuDAO;
	
	@Autowired
	private AgentUserDao agentUserDAO;
	
	@Autowired
	private MgrUserAndMenuDAO mgrUserAndMenuDAO;
	@Autowired
	private MgrUserService mgrUserService;

	protected Logger logger = LoggerFactory.getLogger(getClass());
 
	/**
	 * 获取后台登录用户信息
	 */
	protected MgrUser getMgrUser() {
		Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
		if (authentication == null) {
			throw new ZhuziException(ErrorCode.MgrUser_Not_Exist);
		}
		MgrUserDetail userDetail = (MgrUserDetail) authentication.getPrincipal();
		logger.info("登录用户userName:{}", userDetail.getUsername());
		return userDetail.getUser();
	}
	@RequestMapping(value = "/jsp/mgruser1")
	public String mgrusers(Model model, HttpServletRequest request) {
		request.setAttribute("username", getMgrUser().getName());
		request.setAttribute("menus", mgrUserAndMenuDAO.findMgrMenuByMuserId(getMgrUser().getId()));
		System.out.println("mgruser OK!");
		return "jsp/mgruser";
	}
	
//	@RequestMapping(value = "/findAgents")
//	public String findAgents(Model model, HttpServletRequest request) {
////		request.setAttribute("value", "{\"1\":\"1\",\"2\",\"2\"}");
////		request.setAttribute("display", "{\"1\":\"1\",\"2\",\"2\"}");
//		System.out.println("findAgents OK!");
////		return "mgruser";
//		return "[{\"display\":\"中国嘉靖银行上海分行\",\"value\":\"1\"},{\"display\":\"中国嘉靖银行四川分行\",\"value\":\"2\"},{\"display\":\"中国嘉靖银行云南分行\",\"value\":\"3\"}]";
//	}
	
	

	//生成问候信息


}
